/*
 * facesdkwrapper.h
 *
 *  Created on: 2016年3月25日
 *      Author: guyadong
 */

#ifndef FACESDKTEST_FACESDKWRAPPER_H_
#define FACESDKTEST_FACESDKWRAPPER_H_
#include <vector>
#include <limits>
#include <mutex>
#include <cstring>
#include <sstream>
#include "FD.H"
#include "FR.H"
#include "file_utilits.h"
#include "time_utilits.h"
#include"CimgWrapper.h"
namespace gdface {
#define MAX_FACE_NUM 50
const static FSize DEFAULT_MIN_SIZE{40,40};
const static FSize DEFAULT_MAX_SIZE{std::numeric_limits<short int>::max(),std::numeric_limits<short int>::max()};
using cimg_gray_type=cimg_library::CImg<uint8_t>;
using face_info_type=std::pair<std::vector<FacePos>,std::vector<EyeInfo>>;

class facesdk_wrapper {

public:

	face_info_type detect_face(const uint8_t* gray_img_ptr, uint16_t width, uint16_t height, uint16_t row_stride = 0,
			bool eye = false, double fscale = 1.1, const FSize& min = DEFAULT_MIN_SIZE, const FSize& max =
					DEFAULT_MAX_SIZE) const;
	face_info_type detect_face(const image_matrix_param& gray_img, bool eye = false, double fscale = 1.1,
			const FSize& min = DEFAULT_MIN_SIZE, const FSize& max = DEFAULT_MAX_SIZE) const;
	face_info_type detect_face(const cimg_gray_type& gray_img, bool eye = false, double fscale = 1.1, const FSize& min =
			DEFAULT_MIN_SIZE, const FSize& max = DEFAULT_MAX_SIZE) const;
	/* 
	 * 将检测到的人脸以矩形框方式显示在图像上
	 * share为true时，在原图上画人脸位置矩形，否则不修改原图	
	 **/
	template<typename T, typename ...Args>
	static void display_face_rect(const cimg_library::CImg<T> & src_img
			,const face_info_type& face_list
			,bool shared=false
			,Args&&...args){
		cimg_library::CImg<T> copy;
		cimg_library::CImg<T>& dst=shared?const_cast<cimg_library::CImg<T>&>(src_img):copy =src_img;

		uint8_t color[] = { 255,0,0 };
		uint8_t text_color[] = { 0,255,0 };
		for(size_t i=0;i<face_list.first.size();++i){
			auto face_info=face_list.first[i];
			std::stringstream stream;
			stream << face_info.left << "," << face_info.top<<"\nW"<< face_info.width<<"H"<< face_info.height;
			dst.draw_text(int(face_info.left+1), int(face_info.top+1), stream.str().data(), text_color);
			dst.draw_rectangle(int(face_info.left),int(face_info.top),int(face_info.left+face_info.width),int(face_info.top+face_info.height),color,0.9f, ~0U);
		}
		std::stringstream stream;
		args_print(stream, std::forward<Args>(args)...);
		stream<<" "<<face_list.first.size()<<" faces";
		dst.display(stream.str().data());
	}
	facesdk_wrapper()=default;
	virtual ~facesdk_wrapper()=default;
};



} /* namespace gdface */

#endif /* FACESDKTEST_FACESDKWRAPPER_H_ */
